package com.gxks.lhs.controller.user;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gxks.lhs.constants.R;
import com.gxks.lhs.entity.Evaluation;
import com.gxks.lhs.service.IEvaluationService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 评价信息表 前端控制器
 * </p>
 *
 * @author LuoHaisong
 * @since 2023-06-05
 */
@RestController
@RequestMapping("/restful-api/evaluation")
public class EvaluationController {
    @Autowired
    private IEvaluationService evaluationService;

    @ApiOperation("评价订单")
    @PostMapping("/order")
    public R evaluationOrder(@RequestBody Evaluation evaluation) {
        if (evaluationService.evaluationOrder(evaluation)) {
            return R.success();
        }
        return R.error();
    }

    @ApiOperation("根据订单id查询评价")
    @GetMapping("/queryByOrderId")
    public R queryByOrderId(@RequestParam Integer orderId) {
        Evaluation evaluation = evaluationService.selectEvaluationByOrderId(orderId);
        if (evaluation != null) {
            return R.success(evaluation);
        }
        return R.error();
    }

    @ApiOperation("根据卖家id查询评价")
    @GetMapping("/queryBySellerId")
    public R queryBySellerId(@RequestParam Integer sellerId,
                             @RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
                             @RequestParam(value = "size", required = false, defaultValue = "10") Integer size) {
        Page<Evaluation> evaluationPage = evaluationService.selectEvaluationBySellerId(sellerId, current, size);
        if (evaluationPage != null) {
            return R.success(evaluationPage);
        }
        return R.error();
    }

}

